package com.tju.educms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tju.Result;
import com.tju.educms.entity.CrmBanner;
import com.tju.educms.service.CrmBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author gsc
 * @since 2022-01-11
 */
@RestController
@CrossOrigin
@RequestMapping("/educms/banneradmin")
public class BannerAdminController {

    @Autowired
    CrmBannerService crmBannerService;
    //实现admin对于banner的增删改查操作
    @GetMapping("pageBanner/{page}/{limit}")
    public Result pageBanner(@PathVariable long page,
                             @PathVariable long limit){
        Page<CrmBanner> pageBanner = new Page<>(page, limit);
        crmBannerService.page(pageBanner, null);
        return  Result.ok().data("items",pageBanner.getRecords()).data("total",pageBanner.getTotal());
    }

    //添加banner
    @PostMapping("addBanner")
    public Result addBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.save(crmBanner);
        return Result.ok();
    }
    //根据id获取
    @GetMapping("get/{id}")
    public Result getById(@PathVariable String id){
        CrmBanner banner = crmBannerService.getById(id);
        return Result.ok().data("banner",banner);
    }
    //修改banner
    @PutMapping("update")
    public Result updateById(@RequestBody CrmBanner crmBanner){
        crmBannerService.updateById(crmBanner);
        return Result.ok();
    }
    //删除
    @DeleteMapping("remove/{id}")
    public Result removeById(@PathVariable String id){
        crmBannerService.removeById(id);
        return  Result.ok();
    }


}

